﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace web.core.Controllers
{
    public class publicController : baseController
    {

        public ActionResult error404()
        {
            //All page load
            return View();
        }

        public ActionResult error500()
        {
            //All error load
            return View();
        }

        [PreventDirectAccess]
        public ActionResult ServerError()
        {
            return View("error500");
        }

        [PreventDirectAccess]
        public ActionResult AccessDenied()
        {
            return View("error500");
        }

        public ActionResult NotFound()
        {
            return View("error404");
        }

        [PreventDirectAccess]
        public ActionResult OtherHttpStatusCode(int httpStatusCode)
        {
            return View("GenericHttpError", httpStatusCode);
        }

        private class PreventDirectAccessAttribute : FilterAttribute, IAuthorizationFilter
        {
            public void OnAuthorization(AuthorizationContext filterContext)
            {
                object value = filterContext.RouteData.Values["fromAppErrorEvent"];
                if (!(value is bool && (bool)value))
                    filterContext.Result = new ViewResult
                    {
                        ViewName = "error404"
                        //ViewEngineCollection = "~/Views/Shared/control_error404.ascx"
                    };
            }
        }
    }
}
